package com.paranoidvulture.javaEngine.Utilities;

import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

public class ControlHandler {
	ArrayList<IControl> c;
	
	public ControlHandler() {
		c = new ArrayList<IControl>();
	}
	
	public int Count() {
		return c.size();
	}
	
	public void addToList(IControl i) {
		c.add(i);
	}
	
	public void setActiveStateAll(boolean state) {
		if (!c.isEmpty()) {
			for (int i = 0; i < c.size(); i++) {
				c.get(i).setActive(state);
			}
		}
	}
	
	public void updateControls(long timePassed) {
		if (!c.isEmpty()) {
			for(int i = 0; i < c.size(); i++) {
				c.get(i).update(timePassed);
			}
		} else {
			//DO NOTHING.
		}
	}
	
	public void draw(Graphics2D g) {
		if (!c.isEmpty()) {
			for (int i = 0; i < c.size(); i++) {
				c.get(i).draw(g);
			}
		} else {
			//DO NOTHING.
		}
	}
	
	public IControl getControl(int index) {
		if (!c.isEmpty() && index < c.size()) {
			return c.get(index);
		} else return null;
	}
	
	public void updateKeyEventPressed(KeyEvent e){
		if(!c.isEmpty()){
			for (int i = 0; i < c.size(); i++) {
				c.get(i).keyPressed(e);
			}
		}
	}
	
	//update button released for top view
	public void updateKeyEventReleased(KeyEvent e){
		if(!c.isEmpty()){
			for (int i = 0; i < c.size(); i++) {
				c.get(i).keyReleased(e);
			}
		}
	}
	
	//update button typed or something or another
	public void updateKeyEventTyped(KeyEvent e){
		if(!c.isEmpty()){
			for (int i = 0; i < c.size(); i++) {
				c.get(i).keyTyped(e);
			}
		}
	}
	
	public void updateMouseClicked(MouseEvent e) {		
		if(!c.isEmpty()){
			for (int i = 0; i < c.size(); i++) {
				c.get(i).mouseClicked(e);
			}
		}
	}

	
	public void updateMouseEntered(MouseEvent e) {
		if(!c.isEmpty()){
			for (int i = 0; i < c.size(); i++) {
				c.get(i).mouseEntered(e);
			}
		}
	}

	
	public void updateMouseExited(MouseEvent e) {
		if(!c.isEmpty()){
			for (int i = 0; i < c.size(); i++) {
				c.get(i).mouseExited(e);
			}
		}
	}

	
	public void updateMousePressed(MouseEvent e) {
		if(!c.isEmpty()){
			for (int i = 0; i < c.size(); i++) {
				c.get(i).mousePressed(e);
			}
		}
	}

	
	public void updateMouseReleased(MouseEvent e) {
		if(!c.isEmpty()){
			for (int i = 0; i < c.size(); i++) {
				c.get(i).mouseReleased(e);
			}
		}
	}

	
	public void updateMouseDragged(MouseEvent e) {
		if(!c.isEmpty()){
			for (int i = 0; i < c.size(); i++) {
				c.get(i).mouseDragged(e);
			}
		}
	}

	
	public void updateMouseMoved(MouseEvent e) {
		if(!c.isEmpty()){
			for (int i = 0; i < c.size(); i++) {
				c.get(i).mouseMoved(e);
			}
		}		
	}

}
